<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/2/1 0001
  Time: 下午 7:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>${sessionScope.title}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../admin/css/x-admin.css" media="all">
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="id" value="${id}">
        <input type="hidden" name="type" value="${type}">

        <div class="layui-form-item">
            <label for="userCode" class="layui-form-label">
                <span class="x-red">*</span>登录账户
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userCode" name="userCode" required="" lay-verify="required"
                       autocomplete="off" class="layui-input"  value="${rec.userCode}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>用户姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userName" name="userName" required=""
                       autocomplete="off" class="layui-input" value="${rec.userName}">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>电话号码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone" required="phone"
                       autocomplete="off" class="layui-input" value="${rec.phone}">
            </div>
        </div>



        <%--<div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>角色
            </label>
            <div class="layui-input-inline">
                <select name="roleId" id="roleId" lay-verify="">
                    <c:forEach items="${roleList}" var="rl">
                        <option value="${rl.id}"    <c:if test="${fn:contains(onRole, rl.id)}">selected="selected"</c:if>  >${rl.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>--%>
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_repass" name="password" required="" lay-verify="repass"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="save" lay-submit >
                保存
            </button>
        </div>
    </form>
</div>
<script src="/js/layui/layui.js" charset="utf-8">
</script>
<script src="../../admin/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){

        var form = layui.form
            ,layer = layui.layer;
        var $ = layui.jquery;
        //自定义验证规则
        form.verify({
            nikename: function(value){
                if(value.length < 5){
                    return '昵称至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(save)', function(data){
            console.log(data);
            var userCode = $("#userCode").val();
            if(isNaN(Number(userCode))){
                $.ajax({
                    url:'/adminSystem/getAdmin',
                    type:'POST', //GET
                    async:true,    //或false,是否异步
                    data: data.field,
                    timeout:5000,    //超时时间
                    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    success:function (da) {
                        if(da.code=='true' || ${rec!=null}){
                            $.ajax({
                             url:'/adminSystem/saveAdmin',
                             type:'POST', //GET
                             async:true,    //或false,是否异步
                             data: data.field,
                             timeout:5000,    //超时时间
                             dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                             beforeSend:function(xhr){
                             /*console.log(xhr)
                             console.log('发送前')*/
                             },
                             success:function(data){
                             if (true==data.code || "true"==data.code){
                             layer.alert("保存成功", {icon: 6},function () {
                             // 获得frame索引
                             var index = parent.layer.getFrameIndex(window.name);
                             //关闭当前frame
                             parent.layer.close(index);
                             });
                             }else {
                             layer.alert("保存失败", {icon: 6},function () {
                             // 获得frame索引
                             var index = parent.layer.getFrameIndex(window.name);
                             //关闭当前frame
                             parent.layer.close(index);
                             });
                             }
                             },
                             error:function(xhr,textStatus){
                             console.log('错误')
                             console.log(xhr)
                             console.log(textStatus)
                             },
                             complete:function(){
                             //console.log('结束')
                             }
                             });
                        }else{
                            layer.alert("登录账户重复！")
                        }
                    }
                })
            }else{
                layer.alert("账户不能为纯数字!")
            }
            return false;
        });


    });
</script>

</body>

</html>
